package com.xx.servlet.web;

import java.io.IOException;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.xx.entity.Message;




public class Sendservlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
         String msg=request.getParameter("msg");
         
		HttpSession session=request.getSession();
		String name=(String)session.getAttribute("uname");
		
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
		String time=sdf.format(new Date());
		
		Message m = new Message();
		m.setMsg(msg);
		m.setName(name);
		m.setTime(time);
		ServletContext application=getServletContext();
		List<Message> messageList = (List<Message>) application.getAttribute("msgList");
		if(messageList == null) {
			messageList = new ArrayList<Message>();
		}
		
		
		messageList.add(m);
         application.setAttribute("msgList", messageList);
		
		response.sendRedirect("send.jsp");
	}

}
